﻿using System;
using Foundation;
using Social;
using SpotOffer.iOS.Share;
using SpotOffer.Utils;
using UIKit;
using Xamarin.Forms;

[assembly: Dependency(typeof(ShareImplementation))]
namespace SpotOffer.iOS.Share
{
    public class ShareImplementation : IShare
    {
		public static void Init() 
		{

		}

		public void ShareStatus (string status)
		{
			ShowActionSheet(status);
		}

		public void ShareStatus (string title, string status, string link)
		{
			ShowActionSheet(title, status, link);
		}

		private void ShowActionSheet(string status, string title = "", string link = "")
		{
			var actionSheet = new UIActionSheet("Share on");
			foreach (SLServiceKind service in Enum.GetValues(typeof(SLServiceKind)))
			{
				actionSheet.AddButton(service.ToString());
			}
			actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) {
				SLServiceKind serviceKind = (SLServiceKind)Enum.Parse(typeof(SLServiceKind), actionSheet.ButtonTitle(b.ButtonIndex));
				ShareOnService(serviceKind,title,status,link);
			};
			actionSheet.ShowInView (UIApplication.SharedApplication.KeyWindow.RootViewController.View);
		}

		private void ShareOnService(SLServiceKind service, string title, string status, string link)
		{

            var activityController = new UIActivityViewController(new NSObject[] { UIActivity.FromObject("iphih") }, null);
            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(activityController, true, null);
		}


    }
}
